package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.WaterPriceMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.HashMap;
import java.util.Map;
/**
 * 根据用水类型获取用水价格Id
 * @author 李攀
 *
 */
public class GetWaterPriceId implements ServerInterface {
	
private static Logger logger = LogManager.getLogger(GetWaterPriceId.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<HashMap> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", HashMap.class);

		try { 
			@SuppressWarnings("unchecked")
			Map<String,String> useWaterType = JsonUtils.objectToPojo(req.getData(), Map.class);
			WaterPriceMapper mapper = factory.getMapper(WaterPriceMapper.class);
			if(useWaterType==null||StringUtils.isEmpty(useWaterType.get("id"))) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "id不能为空", void.class);
			}
			//查询用水价格信息
			String  id = mapper.getWaterPriceIdByType(useWaterType.get("id"));
			HashMap<String,String> map=new HashMap<String,String>();
			map.put("id", id);
			info.setData( map);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}
}
